package com.note.simpleshop;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
public class Swagger2 {
    @Value("${swagger2.enable}")
    private boolean enable;
    @Bean
    public Docket app_api() {
        return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/order/**")).build().groupName("订单接口文档").pathMapping("/")
                .apiInfo(apiInfo("AP接口文档V4.4及之前","文档中可以查询及测试接口调用参数和结果","1.0"));
    }

    @Bean
    public Docket createUserRestApi() {
        return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/user/**")).build().groupName("用户接口文档").pathMapping("/")
                .apiInfo(apiInfo("用户模块","文档中可以查询及测试接口调用参数和结果","1.0"));
    }
    @Bean
    public Docket createSystemRestApi() {
        return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/system/**")).build().groupName("系统接口文档").pathMapping("/")
                .apiInfo(apiInfo("AP接口文档V4.4及之前","文档中可以查询及测试接口调用参数和结果","1.0"));
    }
    @Bean
    public Docket createGoodsRestApi() {
        return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/goods/**")).build().groupName("商品接口文档").pathMapping("/")
                .apiInfo(apiInfo("AP接口文档V4.4及之前","文档中可以查询及测试接口调用参数和结果","1.0"));
    }
    @Bean
    public Docket createCartRestApi() {
        return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/cart/**")).build().groupName("购物车接口文档").pathMapping("/")
                .apiInfo(apiInfo("AP接口文档V4.4及之前","文档中可以查询及测试接口调用参数和结果","1.0"));
    }
    @Bean
    public Docket createCouponRestApi() {
        return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/coupon/**")).build().groupName("优惠劵接口文档").pathMapping("/")
                .apiInfo(apiInfo("AP接口文档V4.4及之前","文档中可以查询及测试接口调用参数和结果","1.0"));
    }
    private ApiInfo apiInfo(String name,String description,String version) {
        ApiInfo apiInfo = new ApiInfoBuilder().title(name).description(description).version(version).build();
        return apiInfo;
    }
}
